
$(document).ready(function() {
	$('#enterprise').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 10, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : true, //是否显示（应用）分页器
        "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : true, //是否启动各个字段的排序功能
        "aaSorting" : [[1, "ASC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sPaginationType": "full_numbers",
	    "sAjaxSource":"sys/ClientExt/list_",
        "fnServerData":retrieveData,  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "id",
			"sTitle" : "序号",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		        return '<input type="checkbox" name="id" />';
		     }
		}, {
			"mDataProp" : "clientIdCard",
			"sTitle" : "身份证",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		        return "<a href='javascript:openUpdate(&quot;"+data+"&quot;,&quot;see&quot;);'>"+data+"</a>";
		     }
		}, {
			"mDataProp" : "clientName",
			"sTitle" : "用户名称",
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"20%"
		}, {
			"mDataProp" : "clientSex",
			"sTitle" : "性别",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				return data ==1?"男":"女";
		     }
		}, {
			"mDataProp" : "clientMobile",
			"sTitle" : "手机号",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "clientNative",
			"sTitle" : "身份证地址",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "clientMaritalStatus",
			"sTitle" : "是否结婚",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				return data ==1?"否":"是";
		     }
		},  {
			"mDataProp" : "uid",
			"sTitle" : "操作",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
			
		} ],
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        },
        "fnRowCallback" : function(nRow, aData, iDisplayIndex) {
            /* 用来改写用户权限的 */
            if (aData.clientMaritalStatus != 1){
                $('td:eq(8)', nRow).html("<a href='javascript:openUpdate(&quot;"+aData.eid+"&quot;,&quot;edit&quot;)' title='修改'><img src='icons/item.png'></a><a href='javascript:deleteEnterprise(&quot;"+aData.eid+"&quot;)' title='删除'><img src='icons/del2.png'></a>");                    	
            }else{
            	$('td:eq(8)', nRow).html("<a href='javascript:openUpdate(&quot;"+aData.eid+"&quot;,&quot;edit&quot;)' title='修改'><img src='icons/item.png'></a>");                   
            }
            return nRow;
        }
	});
});
	
	//自定义数据获取函数
	function retrieveData( sSource, aoData, fnCallback ) {
		 aoData.push({"name":"beanProxy[enable]","value": 0});   
	        $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        	
	        });
	}

	//删除企业
	function deleteEnterprise(obj){
			   $.dialog.confirm('是否确定删除选中的企业？', function(){
				   $.ajax( {
		                type: "POST", 
		                url: "enter_deleteEnterprise.action", 
		                cache : false,
		                dataType : "json",
		                data : {
		                	eid : obj
						},
		                success: function(resp) {
		                	top.showInfo(resp.message);
		                	fnDraw();
	             }
		        });
				}, function(){
				    //取消响应事件
				});
	}
	
	//查询
	function fnDraw(){
		$('#enterprise').dataTable().fnDraw();
	}
			
  //跳转修改页面
  function openUpdate(obj,type){
	
	window.location.href ="enter_jumpUI.action?eid="+obj+"&pageType="+type;
  
  }
  
//导出excle
function exExcel(){
	window.open("enter_exportExcel.action?excel=true"+encodeURI(encodeURI(params)));
}